<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>IFE ECMAScript</title>
</head>

<body>
    <input id="first-number" type="number" value="0" placeholder="第一个数字">
    <input id="second-number" type="number" value="0" placeholder="第二个数字">
    <button id="add-btn" >加</button>
    <button id="minus-btn" >减</button>
    <button id="times-btn" >乘</button>
    <button id="divide-btn" >除</button>
    <p id="result">运算结果:</p>
    <script>

        var num1=document.getElementById("first-number");
        var num2=document.getElementById("second-number");
        var addbtn = document.getElementById("add-btn");
        var minusbtn = document.getElementById("minus-btn");
        var timesbtn= document.getElementById("times-btn");
        var dividebtn = document.getElementById("divide-btn");
        var result=document.getElementById("result");

        addbtn.onclick=function(){
            result.innerHTML = parseInt(num1.value)+parseInt(num2.value);
        }
        minusbtn.onclick=function(){
            result.innerHTML = parseInt(num1.value)-parseInt(num2.value);
        }
        timesbtn.onclick=function(){
            result.innerHTML = parseInt(num1.value)*parseInt(num2.value);
        }
        dividebtn.onclick=function(){
            if (num2.value==0) {
                console.log('除数不能为零');
            } else {
                result.innerHTML = parseFloat(num1.value)/parseFloat(num2.value);
            }
            
        }
        
    </script>
</body>

</html>